<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <a href="#/news">新闻</a>
    |
    <a href="#/home">主页</a>

    <fieldset>
        <legend>内容</legend>
        <div id="content"></div>
    </fieldset>

</body>
</html>

<script>
    //hash 模式路由
    //获取hash location.hash  拿到hash值

    //监听hash 改变的方法 onhashchange   渲染页面

    window.onhashchange = function (){
        console.log(location.hash);
        switch(location.hash){
            case "#/news":
                content.innerHTML="<h1>新闻</h1>"
                break
                case "#/home":
                    content.innerHTML="<h1>主页</h1>"
        }

    }

</script>